﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using MyWCFServices.Contracts;
using MyWCFServices.Client.CalculatorServiceClient;
namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
             *方式一 不需要web.config
             */
            //using (ChannelFactory<ICalculator> channelFactory = 
            //    new ChannelFactory<ICalculator>(new WSHttpBinding(),"http://127.0.0.1:9999/CalculatorService"))
            //{
            //    ICalculator proxy = channelFactory.CreateChannel();
            //    using (proxy as IDisposable)
            //    {
            //        Console.WriteLine("x + y = {0}", proxy.Add(1, 2));
            //        Console.WriteLine("x - y = {0}", proxy.Subtract(1, 2));
            //        Console.Read();
            //    }
            //}

            /*
             *方式二 需要web.config calculatorservice
             */
            //using (ChannelFactory<ICalculator> channelFactory = new ChannelFactory<ICalculator>("calculatorservice"))
            //{
            //    ICalculator proxy = channelFactory.CreateChannel();
            //    using (proxy as IDisposable)
            //    {
            //        Console.WriteLine("x + y = {0}", proxy.Add(1, 2));
            //        Console.WriteLine("x - y = {0}", proxy.Subtract(1, 2));
            //        Console.Read();
            //    }
            //}

            /*
             * 方式三 Web Service References
             */
            using (CalculatorServiceClient client = new CalculatorServiceClient())
            {
                Console.WriteLine(client.Add(1,2));
                Console.ReadLine();
            }
        }
    }
}
